package edums.common.model.service;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import edums.common.dto.PagingDTO;
import edums.common.dto.PostDTO;
import edums.common.model.dao.PostDAO;
import edums.common.util.Utilities;

public class PostServiceImpl implements PostService {
	private PostDAO postDAO;
	
	public PostServiceImpl(PostDAO postDAO){
		this.postDAO = postDAO;
	}
	
	@Override
	public Map doGetSearchPost(Map searchInfo) throws SQLException{
		ArrayList pList = (ArrayList) postDAO.selectSearchPost(searchInfo);
		for(Object obj : pList){
			PostDTO pdto = (PostDTO) obj;
			pdto.setPostNo(Utilities.changeZipcodeFormat(pdto.getPostNo()));
		}
		PagingDTO pagingDTO = new PagingDTO(postDAO.selectSearchPostTotalContent(searchInfo), (Integer) searchInfo.get("page"));
		Map map = new HashMap();
		map.put("pList", pList);
		map.put("pagingDTO", pagingDTO);
		return map;
	}
}
